<?php
//上传图片(缩放、加水印)(可以同时上传多张图片,但只有一张会被缩放加水印)
//需要gdimg-0.php支持
header("content-type:text/html;charset=utf-8");
echo"<pre>";
print_r($_FILES);
echo"</pre>";
$arr=$_FILES['upimges'];
$wjhz = array(".txt",".jpg",".png");
if($_FILES['upimges']!=null){
	foreach($arr["error"] as $k=>$v){
		if($v==0){
			$hz=substr($arr["name"][$k], strrpos($arr["name"][$k], "."));
			if(in_array($hz, $wjhz)){
				if($arr["size"][$k]<2200000){
					$filename=mt_rand(1000, 9999).time().mt_rand(1000, 9999).$hz;
					$dizhi="imgs/$filename";
					$sr=move_uploaded_file($arr['tmp_name'][$k], $dizhi);
					if($sr){
						session_start();
						$_SESSION['$dizhi']=$dizhi;
						echo "<script>";
						echo "alert('文件上传成功，并且已经缩放和添加水印！');";
//						header('location:gdimg.php');
						echo "window.location.href='gdimg-0.php';";
						echo "</script>";						
					}else{
						echo "文件上传失败！";
					}
				}else{
					echo"文件过大";
				}
			}else{
				echo "不允许上传的文件类型！";
			}
		}else{
			echo "文件上传出错！";
		}
	}
}
?>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<form action="#" method="post" enctype="multipart/form-data">
			请选择要上传（加水印）的图片：<input type="file" name="upimges[]" multiple="multiple"/>
			<input type="submit" name="" id="" value="上传" />
		</form>
	</body>
</html>